package com.chookss.home.search.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.search.entity.SearchAllEntity;
import com.chookss.home.studyPlan.StudyPlanDetailActivity;
import com.chookss.tools.Utils;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class SearchPlanAdapter extends BaseQuickAdapter<SearchAllEntity.PlanBean.ListBean, BaseViewHolderEx> {
    private Context context;
    private int width, height;
    private String key;

    public SearchPlanAdapter(int layoutResId, Context context, @Nullable List<SearchAllEntity.PlanBean.ListBean> data) {
        super(layoutResId, data);
        this.context = context;

    }

    @Override
    protected void convert(BaseViewHolderEx helper, SearchAllEntity.PlanBean.ListBean item) {
        TextView tvTiltle = helper.getView(R.id.tvSearchPlanTitle);
        TextView tvSearchType = helper.getView(R.id.tvSearchPlanTime);
        TextView tvSearchProvider = helper.getView(R.id.tvSearchPlanProvider);
        tvTiltle.setText(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color),item.getPlanTitle(),key));
        tvSearchType.setText("时间："+Utils.getNormalYMDTime(item.getEffTime())+"-"+Utils.getNormalYMDTime(item.getInvalidTime()));
        if (!Utils.isNull(item.getCreateEmployeeName())) {
            tvSearchProvider.setText("发布人：");
            tvSearchProvider.append(Utils.matcherSearchTitle(context.getResources().getColor(R.color.main_color), item.getCreateEmployeeName(), key));
        }
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, StudyPlanDetailActivity.class);
                intent.putExtra("planCode", item.getPlanCode());
                intent.putExtra("cycle", item.getCycle());
                intent.putExtra("effTime", item.getEffTime());
                intent.putExtra("invalidTime", item.getInvalidTime());
                intent.putExtra("planStatus", item.getPlanStatus());
                context. startActivity(intent);
            }
        });
    }

    public void setKey(String key){
        this.key=key;
    }
}
